'''
可以通过 字符串 操作对象的成员： 函数  --调用
                                                        字段 --修改
'''

class foo:
    def __init__(self,name,age):
        self.name = name
        self.age = age
        
    def show(self):
        return "%s:%s" %(self.name,self.age)
        
        
obj = foo('fuml',18)
var = 'name'

#method 1
print(obj.__dict__)
print(obj.__dict__[var])

#method 2
attr_var = getattr(obj, var)
print(attr_var)

if hasattr(obj, var):
    attr_var = getattr(obj, var)
    print(attr_var)
    setattr(obj, var, 'xieweiyun')
    print('change attribute....')
    attr_var = getattr(obj, var)
    print(attr_var)
    
print('get func attribute....')    
# get func--show
func_var = getattr(obj, 'show')

print(func_var())